package com.example.demo.configure;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginValidateInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler ) {
        //1.获取session中的loginUser
        HttpSession session = request.getSession();
        Object loginUser = session.getAttribute("loginUser");
        //2.loginUser不为null,登录过，放行
        if(loginUser != null){
            return true;
        }
        //3.为null,不放行
        return false;
    }

}
